home *** CD-ROM | disk | FTP | other *** search
/ Turnbull China Bikeride / Turnbull China Bikeride - Disc 2.iso / STUTTGART / LANG / C / LIB / REGEX / <tarZ$use> / files / RegEx / H / Defns < prev    next >
Text File  |  1992-01-12  |  12KB  |  240 lines

  1. /*      > H.Defns - Extended regular expression matching and search     */
  2.  
  3. /* Definitions for data structures callers pass the regex library.
  4.    Copyright (C) 1985 Free Software Foundation, Inc.
  5.  
  6.                        NO WARRANTY
  7.  
  8.   BECAUSE THIS PROGRAM IS LICENSED FREE OF CHARGE, WE PROVIDE ABSOLUTELY
  9. NO WARRANTY, TO THE EXTENT PERMITTED BY APPLICABLE STATE LAW.  EXCEPT
  10. WHEN OTHERWISE STATED IN WRITING, FREE SOFTWARE FOUNDATION, INC,
  11. RICHARD M. STALLMAN AND/OR OTHER PARTIES PROVIDE THIS PROGRAM "AS IS"
  12. WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
  13. BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
  14. FITNESS FOR A PARTICULAR PURPOSE.  THE ENTIRE RISK AS TO THE QUALITY
  15. AND PERFORMANCE OF THE PROGRAM IS WITH YOU.  SHOULD THE PROGRAM PROVE
  16. DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR
  17. CORRECTION.
  18.  
  19.  IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW WILL RICHARD M.
  20. STALLMAN, THE FREE SOFTWARE FOUNDATION, INC., AND/OR ANY OTHER PARTY
  21. WHO MAY MODIFY AND REDISTRIBUTE THIS PROGRAM AS PERMITTED BELOW, BE
  22. LIABLE TO YOU FOR DAMAGES, INCLUDING ANY LOST PROFITS, LOST MONIES, OR
  23. OTHER SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
  24. USE OR INABILITY TO USE (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR
  25. DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY THIRD PARTIES OR
  26. A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS) THIS
  27. PROGRAM, EVEN IF YOU HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH
  28. DAMAGES, OR FOR ANY CLAIM BY ANY OTHER PARTY.
  29.  
  30.                 GENERAL PUBLIC LICENSE TO COPY
  31.  
  32.   1. You may copy and distribute verbatim copies of this source file
  33. as you receive it, in any medium, provided that you conspicuously and
  34. appropriately publish on each copy a valid copyright notice "Copyright
  35. (C) 1985 Free Software Foundation, Inc."; and include following the
  36. copyright notice a verbatim copy of the above disclaimer of warranty
  37. and of this License.  You may charge a distribution fee for the
  38. physical act of transferring a copy.
  39.  
  40.   2. You may modify your copy or copies of this source file or
  41. any portion of it, and copy and distribute such modifications under
  42. the terms of Paragraph 1 above, provided that you also do the following:
  43.  
  44.     a) cause the modified files to carry prominent notices stating
  45.     that you changed the files and the date of any change; and
  46.  
  47.     b) cause the whole of any work that you distribute or publish,
  48.     that in whole or in part contains or is a derivative of this
  49.     program or any part thereof, to be licensed at no charge to all
  50.     third parties on terms identical to those contained in this
  51.     License Agreement (except that you may choose to grant more extensive
  52.     warranty protection to some or all third parties, at your option).
  53.  
  54.     c) You may charge a distribution fee for the physical act of
  55.     transferring a copy, and you may at your option offer warranty
  56.     protection in exchange for a fee.
  57.  
  58. Mere aggregation of another unrelated program with this program (or its
  59. derivative) on a volume of a storage or distribution medium does not bring
  60. the other program under the scope of these terms.
  61.  
  62.   3. You may copy and distribute this program (or a portion or derivative
  63. of it, under Paragraph 2) in object code or executable form under the terms
  64. of Paragraphs 1 and 2 above provided that you also do one of the following:
  65.  
  66.     a) accompany it with the complete corresponding machine-readable
  67.     source code, which must be distributed under the terms of
  68.     Paragraphs 1 and 2 above; or,
  69.  
  70.     b) accompany it with a written offer, valid for at least three
  71.     years, to give any third party free (except for a nominal
  72.     shipping charge) a complete machine-readable copy of the
  73.     corresponding source code, to be distributed under the terms of
  74.     Paragraphs 1 and 2 above; or,
  75.  
  76.     c) accompany it with the information you received as to where the
  77.     corresponding source code may be obtained.  (This alternative is
  78.     allowed only for noncommercial distribution and only if you
  79.     received the program in object code or executable form alone.)
  80.  
  81. For an executable file, complete source code means all the source code for
  82. all modules it contains; but, as a special exception, it need not include
  83. source code for modules which are standard libraries that accompany the
  84. operating system on which the executable file runs.
  85.  
  86.   4. You may not copy, sublicense, distribute or transfer this program
  87. except as expressly provided under this License Agreement.  Any attempt
  88. otherwise to copy, sublicense, distribute or transfer this program is void and
  89. your rights to use the program under this License agreement shall be
  90. automatically terminated.  However, parties who have received computer
  91. software programs from you with this License Agreement will not have
  92. their licenses terminated so long as such parties remain in full compliance.
  93.  
  94.   5. If you wish to incorporate parts of this program into other free
  95. programs whose distribution conditions are different, write to the Free
  96. Software Foundation at 675 Mass Ave, Cambridge, MA 02139.  We have not yet
  97. worked out a simple rule that can be stated here, but we will often permit
  98. this.  We will be guided by the two goals of preserving the free status of
  99. all derivatives of our free software and of promoting the sharing and reuse of
  100. software.
  101.  
  102.  
  103. In other words, you are welcome to use, share and improve this program.
  104. You are forbidden to forbid anyone else to use, share and improve
  105. what you give them.   Help stamp out software-hoarding!  */
  106.  
  107. /***** Macro definitions *****/
  108.  
  109. #define JUMP_LEN        3               /* Length of a jump instruction */
  110.  
  111. #define BITMAP_LEN      ( (UCHAR_MAX + CHAR_BIT) / CHAR_BIT )
  112.                                         /* Number of bytes in a bitmap */
  113.  
  114. #define NONE            (-1)            /* Offset value not set */
  115.  
  116. #define MAX(x,y)        ( (x) > (y) ? (x) : (y) )
  117. #define MAX_ADD         MAX((BITMAP_LEN+2),(JUMP_LEN*3))
  118.                                         /* Maximum number of bytes added to
  119.                                            buffer for a single operator */
  120.  
  121. #define STACK_SIZE      10              /* Levels of bracket nesting */
  122. #define MAX_FAILURES    80              /* Number of failure points stacked */
  123. #define ALLOC_INCR      100             /* Bytes increase per buffer extension */
  124.  
  125. #define FAIL_STACK_INCR 100             /* Increment size for failure stack */
  126.  
  127. #define SIGN_EXTEND_CHAR(x)     ((signed char)(x))
  128. #define SYNTAX(ch)              (re_syntax_table[ch])
  129. #define TRANSLATE(ch)           (translate ? translate[ch] : (ch))
  130.  
  131. #define BACKSLASH_BIT           (1 << CHAR_BIT)
  132. #define BACKSLASH(ch)           ((ch) | BACKSLASH_BIT)
  133. #define IS_BACKSLASH(ch)        ((ch) & BACKSLASH_BIT)
  134. #define LITERAL(ch)             ((ch) & ~BACKSLASH_BIT)
  135.  
  136. #define ADDR(offset)    ((offset) + re->buffer)
  137. #define OFFSET(addr)    ((addr) - re->buffer)
  138. #define SETBIT(b,c)     ( (b)[(c)/CHAR_BIT] |= ( 1 << ((c)%CHAR_BIT) ) )
  139. #define GETBIT(b,c)     ( (b)[(c)/CHAR_BIT] &  ( 1 << ((c)%CHAR_BIT) ) )
  140. #define JUMP_DEST(j)    ( SIGN_EXTEND_CHAR((j)[1]) << CHAR_BIT | (j)[0] )
  141.  
  142. #define MEMNO(ch)       (LITERAL(ch)-'0')
  143.  
  144. #define PATPUSH(ch)     (*b++ = (char)(ch))
  145.  
  146. #define PATUNFETCH(ch)  (IS_BACKSLASH(ch) ? p -= 2 : p--)
  147.  
  148. #define PATFETCH(ch) \
  149. { \
  150.         if ( *p == '\0' ) \
  151.                 goto end_of_pattern; \
  152.         ch = *(unsigned char *)p++; \
  153.         if ( ch != '\\' ) \
  154.                 ch = TRANSLATE(ch); \
  155.         else \
  156.         { \
  157.                 if ( *p == '\0' ) \
  158.                         goto end_of_pattern; \
  159.                 ch = *(unsigned char *)p++; \
  160.                 ch = BACKSLASH(ch); \
  161.         } \
  162. }
  163.  
  164. /* These are the command codes that appear in compiled regular expressions,
  165.    one per byte. Some command codes are followed by argument bytes.
  166.    A command code can specify any interpretation whatever for its arguments.
  167.    Zero-bytes may appear in the compiled regular expression.
  168. */
  169.  
  170. /* ----- 0-character RE's ----- */
  171.  
  172. #define startline       1       /* fails unless at beginning of line */
  173. #define endline         2       /* fails unless at end of line */
  174. #define startbuf        3       /* fails unless at start of buffer */
  175. #define endbuf          4       /* fails unless at end of buffer */
  176. #define startword       5       /* fails unless at start of word */
  177. #define endword         6       /* fails unless at end of word */
  178. #define wordbound       7       /* fails unless at a word boundary */
  179.  
  180. /* ----- 1-character RE's ----- */
  181.  
  182. #define anychar         8       /* matches any one character */
  183. #define wordchar        9       /* matches any word-constituent character */
  184. #define notchar         10      /* matches any character other than that following */
  185.                                 /* Next byte = character to exclude
  186.                                  */
  187. #define charset         11      /* matches any character belonging to specified set */
  188.                                 /* Next byte = bitmap number of bytes
  189.                                    Then comes a bitmap specifying characters
  190.                                    in the set (each byte ordered low bit first)
  191.                                  */
  192.  
  193. /* ----- multi-character RE's ----- */
  194.  
  195. #define duplicate       12      /* matches a duplicate of something remembered */
  196.                                 /* Next byte = index of memory register */
  197. #define exactn          13      /* matches a number of literal bytes */
  198.                                 /* Next byte = number of literal bytes
  199.                                    Then comes that number of characters
  200.                                  */
  201.  
  202. /* ----- RE operators: jumps ----- */
  203.  
  204. /* All jumps are followed by JUMP_LEN-1 bytes containing relative jump */
  205.  
  206. #define jump                    14      /* Always jump */
  207. #define on_failure_jump         15      /* Save destination. If match fails,
  208.                                            use saved destination as restart
  209.                                            point.
  210.                                          */
  211. #define finalise_jump           16      /* Throw away the latest saved failure
  212.                                            destination, and jump
  213.                                          */
  214. #define maybe_finalise_jump     17      /* Jump with the possibility of
  215.                                            finalisation. The procedure
  216.                                            `resolve_jumps' converts this
  217.                                            to "jump" or "finalise_jump",
  218.                                            depending on whether or not the
  219.                                            next portion of the pattern could
  220.                                            match the same as the jump
  221.                                            destination point.
  222.                                          */
  223. #define dummy_failure_jump      18      /* Jump and push a dummy failure
  224.                                            point. This will be thrown away if
  225.                                            used as a failure destination.
  226.                                          */
  227.  
  228. /* ----- RE operators: memory ----- */
  229.  
  230. /* Both followed by 1 byte containing register number (1-NREGS) */
  231.  
  232. #define start_memory            19      /* remember start of text */
  233. #define stop_memory             20      /* remember end of text */
  234.  
  235. /* ----- RE operators: negated RE code ----- */
  236.  
  237. #define NOT_BIT         (1 << (CHAR_BIT-1))
  238. #define NOT(op)         ((op) | NOT_BIT)
  239. #define IS_NOT(op)      ((op) & NOT_BIT)
  240.